package net.rlair.sbdemo.dao.mybatis.bootmapper;

import net.rlair.sbdemo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.domain.Pageable;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM t_user")
    List<User> selectUser();

    @Insert("insert into t_user values(#{user.id},#{user.name},#{user.password},1,#{user.created},#{user.updated})")
    int addUser(@Param("user") User user);

    @Update("update t_user set name = #{user.name},updated=#{user.updated} where id = #{user.id}")
    int updateNameById(@Param("user") User user);

    @Select("SELECT * FROM t_user where id = #{id}")
    User selectById(@Param("id") int id);

    @Select("SELECT * FROM t_user limit #{page.offset}, #{page.pageSize}")
    List<User> selectPage(@Param("page") Pageable page);

    @Select("SELECT COUNT(1) FROM t_user")
    int countUser();

}

